package demo10;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int result = chaZhi(n);
        System.out.println(result);
    }

    private static int chaZhi(int n) {
        if (n == 1){
            return 0;
        }

        int[] arr = new int[1000];
        arr[0] = 0;
        arr[1] = 1;
        int i = 2;
        while (true){
            arr[i] = arr[i - 1] + arr[i - 2];
            if (n < arr[i]){
                int left = n - arr[i-1];
                int right = arr[i] - n;
                if (left>right){
                    return right;
                } else if (right > left) {
                    return left;
                }else {
                    return left;
                }
            }
            i++;
        }
    }
}
